<?php
/**
 *
 */
abstract class LoaderFactory
{
    static private $loader          = null; #实例

    static public function getLoader()
    {
        //再次调用，直接返回
        if ( self::$loader )
        {
            return self::$loader;
        }

        /**
         * 初次->实例化(1.)->初始化信息(2.3.4.5.)
         */
        self::loadClassLoader();
        $loader     = self::$loader = new ulue\autoload\ClassLoader;

        $includeMap = require __DIR__.'/include_path.php';
        array_push($includeMap, get_include_path());
        set_include_path( implode(PATH_SEPARATOR, $includeMap) );
        $loader->setIncludeMap($includeMap);//

        $npMap      = require __DIR__.'/autoload_namespace.php';
        foreach ($npMap as $namespace => $path) {
            $loader->setNs($namespace, $path);
        }

        $classMap   = require __DIR__.'/autoload_classes.php';
        if ($classMap) {
            $loader->addClassMap($classMap);
        }

        $callback   = require __DIR__.'/autoload_callback.php';
        if ($callback) {
            $loader->setCallback($callback);
        }

        $loader->register();

        $files      = require __DIR__.'/autoload_files.php';
        foreach ($files as $file) {
            require $file;
        }

        return $loader;
    }

    static public function loadClassLoader()
    {
        require __DIR__.'/ClassLoader.php';
    }
}

return LoaderFactory::getLoader();

